package template.practice_02;

import java.util.concurrent.TimeUnit;

/**
 * @author yi qiang
 * @date 2021/9/11 0:41
 */
public abstract class AbsHandler {

    /**
     * 预处理
     */
    public abstract void preHandle();

    /**
     * 处理
     */
    public abstract void handle();

    /**
     * 后处理
     */
    public abstract void postHandle();

    public void sleep(){
        System.out.println("杂事插入,暂停一会");
        try {
            TimeUnit.MILLISECONDS.sleep(20);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


    public void process() {
        preHandle();
        long t=System.currentTimeMillis();
        handle();
        sleep();
        System.out.println("持续了 ==> "+(System.currentTimeMillis()-t)+"ms");
        postHandle();
    }


}
